/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.core.loader;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * 自定义类加载器
 * @author Mr.xiao <matilto:admin@noarm.com>
 * @since jdk1.6
 */
public class ClassLoader {
	private static Method addURL = initAddMethod();
    private static URLClassLoader classloader = (URLClassLoader) java.lang.ClassLoader.getSystemClassLoader();
    
    private static Method initAddMethod() {
        try {
            Method add = URLClassLoader.class.getDeclaredMethod("addURL",
                    new Class[] { URL.class });
            add.setAccessible(true);
            return add;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    
    public static void addJar(URL url) {
        try {
            addURL.invoke(classloader, new Object[] { url });
        }
        catch (Exception e) {
        }
    }
}
